home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / gettimeofday / RCS / gettimeofday.c,v < prev   
Encoding:
Text File  |  1992-05-22  |  3.9 KB  |  182 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     92.05.21.20.11.10;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     89.11.01.02.05.51;  author douglis;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     89.11.01.02.03.39;  author douglis;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @original version (getpid.c) to be modified
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @Add option to disable use of copyout.  Lint.
  33. @
  34. text
  35. @/* 
  36.  * gettimeofday.c --
  37.  *
  38.  *    This file is a benchmark program to measure the cost of a
  39.  *    minimal kernel call (gettimeofday).  It should be invoked as follows:
  40.  *    
  41.  *    gettimeofday [-n] count
  42.  *
  43.  *    Where count is the number of calls to make.  It makes that
  44.  *    many calls, then prints out the average time per call.  If -n is 
  45.  *    specified, then the gettimeofday calls don't actually ask for the 
  46.  *    time.  The difference between a run with -n and a run without -n 
  47.  *    should be the time to copy the current time-of-day to user space.
  48.  *
  49.  * Copyright 1989 Regents of the University of California
  50.  * Permission to use, copy, modify, and distribute this
  51.  * software and its documentation for any purpose and without
  52.  * fee is hereby granted, provided that the above copyright
  53.  * notice appear in all copies.  The University of California
  54.  * makes no representations about the suitability of this
  55.  * software for any purpose.  It is provided "as is" without
  56.  * express or implied warranty.
  57.  */
  58.  
  59. #ifndef lint
  60. static char rcsid[] = "$Header: /sprite/src/benchmarks/gettimeofday/RCS/gettimeofday.c,v 1.2 89/11/01 02:05:51 douglis Exp Locker: kupfer $ SPRITE (Berkeley)";
  61. #endif /* not lint */
  62.  
  63. #include <stdio.h>
  64. #include <sys/time.h>
  65. #include <sys/resource.h>
  66.  
  67. main(argc, argv)
  68.     int argc;
  69.     char **argv;
  70. {
  71.     int count, i;
  72. #ifdef GETRUSAGE
  73.     struct rusage begin ,end;
  74. #endif
  75.     struct timeval start, stop, dummy;
  76.     struct timeval *dummyPtr;
  77.     int micros;
  78.     double timePer;
  79.     char *usage = "Usage: gettimeofday [-n] count\n";
  80.  
  81.     if (argc < 2) {
  82.     fprintf(stderr, usage);
  83.     exit(1);
  84.     }
  85.  
  86.     if (argc > 2 && strcmp(argv[1], "-n") == 0) {
  87.     dummyPtr = NULL;
  88.     --argc;
  89.     ++argv;
  90.     } else if (argc > 2) {
  91.     fprintf(stderr, usage);
  92.     exit(1);
  93.     } else {
  94.     dummyPtr = &dummy;
  95.     }
  96.     count = atoi(argv[1]);
  97.  
  98. #ifdef GETRUSAGE
  99.     getrusage(RUSAGE_SELF, &begin);
  100. #else
  101.     gettimeofday(&start, (struct timezone *) NULL);
  102. #endif
  103.  
  104.     for (i = 0; i < count; i++) {
  105.         (void) gettimeofday(dummyPtr, (struct timezone *) NULL);
  106.     }
  107. #ifdef GETRUSAGE
  108.     getrusage(RUSAGE_SELF, &end);
  109.     micros = (end.ru_utime.tv_sec + end.ru_stime.tv_sec
  110.         - begin.ru_utime.tv_sec - begin.ru_stime.tv_sec)*1000000
  111.         + (end.ru_utime.tv_usec - begin.ru_utime.tv_usec)
  112.         + (end.ru_stime.tv_usec - begin.ru_stime.tv_usec);
  113. #else
  114.     gettimeofday(&stop, (struct timezone *) NULL);
  115.     micros = 1000000*(stop.tv_sec - start.tv_sec)
  116.         + stop.tv_usec - start.tv_usec;
  117. #endif
  118.     timePer = micros;
  119.     printf("Time per iteration: %.2f microseconds\n", timePer/count);
  120. }
  121. @
  122.  
  123.  
  124. 1.2
  125. log
  126. @changed to really do gettimeofday
  127. @
  128. text
  129. @d7 1
  130. a7 1
  131.  *    gettimeofday count
  132. d10 4
  133. a13 1
  134.  *    many calls, then prints out the average time per call.
  135. d26 1
  136. a26 1
  137. static char rcsid[] = "$Header: /sprite/src/benchmarks/gettimeofday/RCS/gettimeofday.c,v 1.1 89/08/31 13:19:47 ouster Exp $ SPRITE (Berkeley)";
  138. d38 1
  139. d40 1
  140. d42 1
  141. a42 1
  142.     struct timezone tz;
  143. d45 1
  144. d47 2
  145. a48 2
  146.     if (argc != 2) {
  147.     fprintf(stderr, "Usage: gettimeofday count\n");
  148. d52 10
  149. d71 1
  150. a71 1
  151.         (void) gettimeofday(&dummy, (struct timezone *) NULL);
  152. @
  153.  
  154.  
  155. 1.1
  156. log
  157. @Initial revision
  158. @
  159. text
  160. @d2 1
  161. a2 1
  162.  * getpid.c --
  163. d5 1
  164. a5 1
  165.  *    minimal kernel call (getpid).  It should be invoked as follows:
  166. d7 1
  167. a7 1
  168.  *    getpid count
  169. d23 1
  170. a23 1
  171. static char rcsid[] = "$Header: /sprite/src/benchmarks/getpid/RCS/getpid.c,v 1.1 89/08/31 13:19:47 ouster Exp $ SPRITE (Berkeley)";
  172. d36 1
  173. a36 1
  174.     struct timeval start, stop;
  175. d42 1
  176. a42 1
  177.     fprintf(stderr, "Usage: getpid count\n");
  178. d55 1
  179. a55 1
  180.         (void) getpid();
  181. @
  182.